<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>datasource.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_datasource_datasource.js.html">datasource.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Generic rich data access API.
<a name="line17"></a> *
<a name="line18"></a> * See http://wiki/Main/ClientDataSource
<a name="line19"></a> *
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.ds.BaseDataNode&#39;);
<a name="line24"></a>goog.provide(&#39;goog.ds.BasicNodeList&#39;);
<a name="line25"></a>goog.provide(&#39;goog.ds.DataNode&#39;);
<a name="line26"></a>goog.provide(&#39;goog.ds.DataNodeList&#39;);
<a name="line27"></a>goog.provide(&#39;goog.ds.EmptyNodeList&#39;);
<a name="line28"></a>goog.provide(&#39;goog.ds.LoadState&#39;);
<a name="line29"></a>goog.provide(&#39;goog.ds.SortedNodeList&#39;);
<a name="line30"></a>goog.provide(&#39;goog.ds.Util&#39;);
<a name="line31"></a>goog.provide(&#39;goog.ds.logger&#39;);
<a name="line32"></a>
<a name="line33"></a>goog.require(&#39;goog.array&#39;);
<a name="line34"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>/**
<a name="line38"></a> * Interface for node in rich data tree.
<a name="line39"></a> *
<a name="line40"></a> * Names that are reserved for system use and shouldn&#39;t be used for data node
<a name="line41"></a> * names: eval, toSource, toString, unwatch, valueOf, watch. Behavior is
<a name="line42"></a> * undefined if these names are used.
<a name="line43"></a> *
<a name="line44"></a> * @constructor
<a name="line45"></a> */
<a name="line46"></a>goog.ds.DataNode = function() {};
<a name="line47"></a>
<a name="line48"></a>
<a name="line49"></a>/**
<a name="line50"></a> * Get the value of the node
<a name="line51"></a> * @return {Object} The value of the node, or null if no value.
<a name="line52"></a> */
<a name="line53"></a>goog.ds.DataNode.prototype.get = goog.nullFunction;
<a name="line54"></a>
<a name="line55"></a>/**
<a name="line56"></a> * Set the value of the node
<a name="line57"></a> * @param {Object} value The new value of the node.
<a name="line58"></a> */
<a name="line59"></a>goog.ds.DataNode.prototype.set = goog.nullFunction;
<a name="line60"></a>
<a name="line61"></a>
<a name="line62"></a>/**
<a name="line63"></a> * Gets all of the child nodes of the current node.
<a name="line64"></a> * Should return an empty DataNode list if no child nodes.
<a name="line65"></a> * @param {string} opt_selector String selector to choose child nodes.
<a name="line66"></a> * @return {goog.ds.DataNodeList} The child nodes.
<a name="line67"></a> */
<a name="line68"></a>goog.ds.DataNode.prototype.getChildNodes = goog.nullFunction;
<a name="line69"></a>
<a name="line70"></a>
<a name="line71"></a>/**
<a name="line72"></a> * Gets a named child node of the current node
<a name="line73"></a> * @param {string} name The node name.
<a name="line74"></a> * @param {boolean} opt_canCreate Whether to create a child node if it does not
<a name="line75"></a> *     exist.
<a name="line76"></a> * @return {goog.ds.DataNode} The child node, or null
<a name="line77"></a> * if no node of this name exists.
<a name="line78"></a> */
<a name="line79"></a>goog.ds.DataNode.prototype.getChildNode = goog.nullFunction;
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Gets the value of a child node
<a name="line84"></a> * @param {string} name The node name.
<a name="line85"></a> * @return {Object} The value of the node, or null if no value or the child node
<a name="line86"></a> *     doesn&#39;t exist.
<a name="line87"></a> */
<a name="line88"></a>goog.ds.DataNode.prototype.getChildNodeValue = goog.nullFunction;
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Sets a named child node of the current node.
<a name="line93"></a> *
<a name="line94"></a> * @param {string} name The node name.
<a name="line95"></a> * @param {Object} value The value to set, can be DataNode, object, property,
<a name="line96"></a> *     or null. If value is null, removes the child node.
<a name="line97"></a> * @return {Object} The child node, if the node was set.
<a name="line98"></a> */
<a name="line99"></a>goog.ds.DataNode.prototype.setChildNode = goog.nullFunction;
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Get the name of the node relative to the parent node
<a name="line104"></a> * @return {string} The name of the node.
<a name="line105"></a> */
<a name="line106"></a>goog.ds.DataNode.prototype.getDataName = goog.nullFunction;
<a name="line107"></a>
<a name="line108"></a>
<a name="line109"></a>/**
<a name="line110"></a> * Set the name of the node relative to the parent node
<a name="line111"></a> * @param {string} name The name of the node.
<a name="line112"></a> */
<a name="line113"></a>goog.ds.DataNode.prototype.setDataName = goog.nullFunction;
<a name="line114"></a>
<a name="line115"></a>
<a name="line116"></a>/**
<a name="line117"></a> * Gets the a qualified data path to this node
<a name="line118"></a> * @return {string} The data path.
<a name="line119"></a> */
<a name="line120"></a>goog.ds.DataNode.prototype.getDataPath = goog.nullFunction;
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * Load or reload the backing data for this node
<a name="line125"></a> */
<a name="line126"></a>goog.ds.DataNode.prototype.load = goog.nullFunction;
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Gets the state of the backing data for this node
<a name="line131"></a> * @return {goog.ds.LoadState} The state.
<a name="line132"></a> */
<a name="line133"></a>goog.ds.DataNode.prototype.getLoadState = null;
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Whether the value of this node is a homogeneous list of data
<a name="line138"></a> * @return {boolean} True if a list.
<a name="line139"></a> */
<a name="line140"></a>goog.ds.DataNode.prototype.isList = goog.nullFunction;
<a name="line141"></a>
<a name="line142"></a>
<a name="line143"></a>/**
<a name="line144"></a> * Enum for load state of a DataNode.
<a name="line145"></a> * @enum {string}
<a name="line146"></a> */
<a name="line147"></a>goog.ds.LoadState = {
<a name="line148"></a>  LOADED: &#39;LOADED&#39;,
<a name="line149"></a>  LOADING: &#39;LOADING&#39;,
<a name="line150"></a>  FAILED: &#39;FAILED&#39;,
<a name="line151"></a>  NOT_LOADED: &#39;NOT_LOADED&#39;
<a name="line152"></a>};
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Base class for data node functionality, has default implementations for
<a name="line157"></a> * many of the functions.
<a name="line158"></a> *
<a name="line159"></a> * implements goog.ds.DataNode
<a name="line160"></a> * @constructor
<a name="line161"></a> */
<a name="line162"></a>goog.ds.BaseDataNode = function() {};
<a name="line163"></a>
<a name="line164"></a>
<a name="line165"></a>/**
<a name="line166"></a> * Set the value of the node
<a name="line167"></a> * @param {Object} value The new value of the node.
<a name="line168"></a> */
<a name="line169"></a>goog.ds.BaseDataNode.prototype.set = goog.nullFunction;
<a name="line170"></a>
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Gets all of the child nodes of the current node.
<a name="line174"></a> * Should return an empty DataNode list if no child nodes.
<a name="line175"></a> * @param {string} opt_selector String selector to choose child nodes.
<a name="line176"></a> * @return {goog.ds.DataNodeList} The child nodes.
<a name="line177"></a> */
<a name="line178"></a>goog.ds.BaseDataNode.prototype.getChildNodes = function(opt_selector) {
<a name="line179"></a>  return new goog.ds.EmptyNodeList();
<a name="line180"></a>};
<a name="line181"></a>
<a name="line182"></a>
<a name="line183"></a>/**
<a name="line184"></a> * Gets a named child node of the current node
<a name="line185"></a> * @param {string} name The node name.
<a name="line186"></a> * @param {boolean} opt_canCreate Whether you can create the child node if
<a name="line187"></a> *     it doesn&#39;t exist already.
<a name="line188"></a> * @return {goog.ds.DataNode} The child node, or null if no node of
<a name="line189"></a> *     this name exists and opt_create is false.
<a name="line190"></a> */
<a name="line191"></a>goog.ds.BaseDataNode.prototype.getChildNode = function(name, opt_canCreate) {
<a name="line192"></a>  return null;
<a name="line193"></a>};
<a name="line194"></a>
<a name="line195"></a>
<a name="line196"></a>/**
<a name="line197"></a> * Gets the value of a child node
<a name="line198"></a> * @param {string} name The node name.
<a name="line199"></a> * @return {Object?} The value of the node, or null if no value or the
<a name="line200"></a> *     child node doesn&#39;t exist.
<a name="line201"></a> */
<a name="line202"></a>goog.ds.BaseDataNode.prototype.getChildNodeValue = function(name) {
<a name="line203"></a>  return null;
<a name="line204"></a>};
<a name="line205"></a>
<a name="line206"></a>
<a name="line207"></a>/**
<a name="line208"></a> * Gets the a qualified data path to this node
<a name="line209"></a> * @return {string} The data path.
<a name="line210"></a> */
<a name="line211"></a>goog.ds.BaseDataNode.prototype.getDataPath = function() {
<a name="line212"></a>  var parentPath = &#39;&#39;;
<a name="line213"></a>  var myName = this.getDataName();
<a name="line214"></a>  if (this.getParent_ &amp;&amp; this.getParent_()) {
<a name="line215"></a>    parentPath = this.getParent_().getDataPath() +
<a name="line216"></a>        (myName.indexOf(goog.ds.STR_ARRAY_START) != -1 ? &#39;&#39; :
<a name="line217"></a>        goog.ds.STR_PATH_SEPARATOR);
<a name="line218"></a>  }
<a name="line219"></a>
<a name="line220"></a>  return parentPath + myName;
<a name="line221"></a>};
<a name="line222"></a>
<a name="line223"></a>
<a name="line224"></a>/**
<a name="line225"></a> * Load or reload the backing data for this node
<a name="line226"></a> */
<a name="line227"></a>goog.ds.BaseDataNode.prototype.load = goog.nullFunction;
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/**
<a name="line231"></a> * Gets the state of the backing data for this node
<a name="line232"></a> * @return {goog.ds.LoadState} The state.
<a name="line233"></a> */
<a name="line234"></a>goog.ds.BaseDataNode.prototype.getLoadState = function() {
<a name="line235"></a>  return goog.ds.LoadState.LOADED;
<a name="line236"></a>};
<a name="line237"></a>
<a name="line238"></a>
<a name="line239"></a>/**
<a name="line240"></a> * Gets the parent node. Subclasses implement this function
<a name="line241"></a> * @type {Function?}
<a name="line242"></a> * @protected
<a name="line243"></a> * @suppress {underscore}
<a name="line244"></a> */
<a name="line245"></a>goog.ds.BaseDataNode.prototype.getParent_ = null;
<a name="line246"></a>
<a name="line247"></a>
<a name="line248"></a>/**
<a name="line249"></a> * Interface for node list in rich data tree.
<a name="line250"></a> *
<a name="line251"></a> * Has both map and list-style accessors
<a name="line252"></a> *
<a name="line253"></a> * @constructor
<a name="line254"></a> * @extends {goog.ds.DataNode}
<a name="line255"></a> */
<a name="line256"></a>// TODO: Use interfaces when available.
<a name="line257"></a>goog.ds.DataNodeList = function() {};
<a name="line258"></a>
<a name="line259"></a>
<a name="line260"></a>/**
<a name="line261"></a> * Add a node to the node list.
<a name="line262"></a> * If the node has a dataName, uses this for the key in the map.
<a name="line263"></a> *
<a name="line264"></a> * @param {goog.ds.DataNode} node The node to add.
<a name="line265"></a> */
<a name="line266"></a>goog.ds.DataNodeList.prototype.add = goog.nullFunction;
<a name="line267"></a>
<a name="line268"></a>
<a name="line269"></a>/**
<a name="line270"></a> * Get a node by string key.
<a name="line271"></a> * Returns null if node doesn&#39;t exist.
<a name="line272"></a> *
<a name="line273"></a> * @param {string} key String lookup key.
<a name="line274"></a> * @return {goog.ds.DataNode} The node, or null if doesn&#39;t exist.
<a name="line275"></a> */
<a name="line276"></a>goog.ds.DataNodeList.prototype.get = goog.nullFunction;
<a name="line277"></a>
<a name="line278"></a>
<a name="line279"></a>/**
<a name="line280"></a> * Get a node by index
<a name="line281"></a> * Returns null if the index is out of range
<a name="line282"></a> *
<a name="line283"></a> * @param {number} index The index of the node.
<a name="line284"></a> * @return {goog.ds.DataNode} The node, or null if doesn&#39;t exist.
<a name="line285"></a> */
<a name="line286"></a>goog.ds.DataNodeList.prototype.getByIndex = goog.nullFunction;
<a name="line287"></a>
<a name="line288"></a>
<a name="line289"></a>/**
<a name="line290"></a> * Gets the size of the node list
<a name="line291"></a> *
<a name="line292"></a> * @return {number} The size of the list.
<a name="line293"></a> */
<a name="line294"></a>goog.ds.DataNodeList.prototype.getCount = goog.nullFunction;
<a name="line295"></a>
<a name="line296"></a>
<a name="line297"></a>/**
<a name="line298"></a> * Sets a node in the list of a given name
<a name="line299"></a> * @param {string} name Name of the node.
<a name="line300"></a> * @param {goog.ds.DataNode} node The node.
<a name="line301"></a> */
<a name="line302"></a>goog.ds.DataNodeList.prototype.setNode = goog.nullFunction;
<a name="line303"></a>
<a name="line304"></a>
<a name="line305"></a>/**
<a name="line306"></a> * Removes a node in the list of a given name
<a name="line307"></a> * @param {string} name Name of the node.
<a name="line308"></a> * @return {boolean} True if node existed and was deleted.
<a name="line309"></a> */
<a name="line310"></a>goog.ds.DataNodeList.prototype.removeNode = goog.nullFunction;
<a name="line311"></a>
<a name="line312"></a>
<a name="line313"></a>/**
<a name="line314"></a> * Simple node list implementation with underlying array and map
<a name="line315"></a> * implements goog.ds.DataNodeList.
<a name="line316"></a> *
<a name="line317"></a> * Names that are reserved for system use and shouldn&#39;t be used for data node
<a name="line318"></a> * names: eval, toSource, toString, unwatch, valueOf, watch. Behavior is
<a name="line319"></a> * undefined if these names are used.
<a name="line320"></a> *
<a name="line321"></a> * @param {Array.&lt;goog.ds.DataNode&gt;} opt_nodes optional nodes to add to list.
<a name="line322"></a> * @constructor
<a name="line323"></a> * @extends {goog.ds.DataNodeList}
<a name="line324"></a> */
<a name="line325"></a>// TODO: Use interfaces when available.
<a name="line326"></a>goog.ds.BasicNodeList = function(opt_nodes) {
<a name="line327"></a>  this.map_ = {};
<a name="line328"></a>  this.list_ = [];
<a name="line329"></a>  this.indexMap_ = {};
<a name="line330"></a>  if (opt_nodes) {
<a name="line331"></a>    for (var i = 0, node; node = opt_nodes[i]; i++) {
<a name="line332"></a>      this.add(node);
<a name="line333"></a>    }
<a name="line334"></a>  }
<a name="line335"></a>};
<a name="line336"></a>
<a name="line337"></a>
<a name="line338"></a>/**
<a name="line339"></a> * Add a node to the node list.
<a name="line340"></a> * If the node has a dataName, uses this for the key in the map.
<a name="line341"></a> * TODO Remove function as well
<a name="line342"></a> *
<a name="line343"></a> * @param {goog.ds.DataNode} node The node to add.
<a name="line344"></a> */
<a name="line345"></a>goog.ds.BasicNodeList.prototype.add = function(node) {
<a name="line346"></a>  this.list_.push(node);
<a name="line347"></a>  var dataName = node.getDataName();
<a name="line348"></a>  if (dataName) {
<a name="line349"></a>    this.map_[dataName] = node;
<a name="line350"></a>    this.indexMap_[dataName] = this.list_.length - 1;
<a name="line351"></a>  }
<a name="line352"></a>};
<a name="line353"></a>
<a name="line354"></a>
<a name="line355"></a>/**
<a name="line356"></a> * Get a node by string key.
<a name="line357"></a> * Returns null if node doesn&#39;t exist.
<a name="line358"></a> *
<a name="line359"></a> * @param {string} key String lookup key.
<a name="line360"></a> * @return {goog.ds.DataNode} The node, or null if doesn&#39;t exist.
<a name="line361"></a> */
<a name="line362"></a>goog.ds.BasicNodeList.prototype.get = function(key) {
<a name="line363"></a>  return this.map_[key] || null;
<a name="line364"></a>};
<a name="line365"></a>
<a name="line366"></a>
<a name="line367"></a>/**
<a name="line368"></a> * Get a node by index
<a name="line369"></a> * Returns null if the index is out of range
<a name="line370"></a> *
<a name="line371"></a> * @param {number} index The index of the node.
<a name="line372"></a> * @return {goog.ds.DataNode} The node, or null if doesn&#39;t exist.
<a name="line373"></a> */
<a name="line374"></a>goog.ds.BasicNodeList.prototype.getByIndex = function(index) {
<a name="line375"></a>  return this.list_[index] || null;
<a name="line376"></a>};
<a name="line377"></a>
<a name="line378"></a>
<a name="line379"></a>/**
<a name="line380"></a> * Gets the size of the node list
<a name="line381"></a> *
<a name="line382"></a> * @return {number} The size of the list.
<a name="line383"></a> */
<a name="line384"></a>goog.ds.BasicNodeList.prototype.getCount = function() {
<a name="line385"></a>  return this.list_.length;
<a name="line386"></a>};
<a name="line387"></a>
<a name="line388"></a>
<a name="line389"></a>/**
<a name="line390"></a> * Sets a node in the list of a given name
<a name="line391"></a> * @param {string} name Name of the node.
<a name="line392"></a> * @param {goog.ds.DataNode} node The node.
<a name="line393"></a> */
<a name="line394"></a>goog.ds.BasicNodeList.prototype.setNode = function(name, node) {
<a name="line395"></a>  if (node == null) {
<a name="line396"></a>    this.removeNode(name);
<a name="line397"></a>  } else {
<a name="line398"></a>    var existingNode = this.indexMap_[name];
<a name="line399"></a>    if (existingNode != null) {
<a name="line400"></a>      this.map_[name] = node;
<a name="line401"></a>      this.list_[existingNode] = node;
<a name="line402"></a>    } else {
<a name="line403"></a>      this.add(node);
<a name="line404"></a>    }
<a name="line405"></a>  }
<a name="line406"></a>};
<a name="line407"></a>
<a name="line408"></a>
<a name="line409"></a>/**
<a name="line410"></a> * Removes a node in the list of a given name
<a name="line411"></a> * @param {string} name Name of the node.
<a name="line412"></a> * @return {boolean} True if node existed and was deleted.
<a name="line413"></a> */
<a name="line414"></a>goog.ds.BasicNodeList.prototype.removeNode = function(name) {
<a name="line415"></a>  var existingNode = this.indexMap_[name];
<a name="line416"></a>  if (existingNode != null) {
<a name="line417"></a>    this.list_.splice(existingNode, 1);
<a name="line418"></a>    delete this.map_[name];
<a name="line419"></a>    delete this.indexMap_[name];
<a name="line420"></a>    for (var index in this.indexMap_) {
<a name="line421"></a>      if (this.indexMap_[index] &gt; existingNode) {
<a name="line422"></a>        this.indexMap_[index]--;
<a name="line423"></a>      }
<a name="line424"></a>    }
<a name="line425"></a>  }
<a name="line426"></a>  return existingNode != null;
<a name="line427"></a>};
<a name="line428"></a>
<a name="line429"></a>
<a name="line430"></a>/**
<a name="line431"></a> * Get the index of a named node
<a name="line432"></a> * @param {string} name The name of the node to get the index of.
<a name="line433"></a> * @return {number|undefined} The index.
<a name="line434"></a> */
<a name="line435"></a>goog.ds.BasicNodeList.prototype.indexOf = function(name) {
<a name="line436"></a>  return this.indexMap_[name];
<a name="line437"></a>};
<a name="line438"></a>
<a name="line439"></a>
<a name="line440"></a>/**
<a name="line441"></a> * Immulatable empty node list
<a name="line442"></a> * @extends {goog.ds.BasicNodeList}
<a name="line443"></a> * @constructor
<a name="line444"></a> */
<a name="line445"></a>
<a name="line446"></a>goog.ds.EmptyNodeList = function() {
<a name="line447"></a>  goog.ds.BasicNodeList.call(this);
<a name="line448"></a>};
<a name="line449"></a>goog.inherits(goog.ds.EmptyNodeList, goog.ds.BasicNodeList);
<a name="line450"></a>
<a name="line451"></a>
<a name="line452"></a>/**
<a name="line453"></a> * Add a node to the node list.
<a name="line454"></a> * If the node has a dataName, uses this for the key in the map.
<a name="line455"></a> *
<a name="line456"></a> * @param {goog.ds.DataNode} node The node to add.
<a name="line457"></a> */
<a name="line458"></a>goog.ds.EmptyNodeList.prototype.add = function(node) {
<a name="line459"></a>  throw Error(&#39;Can\&#39;t add to EmptyNodeList&#39;);
<a name="line460"></a>};
<a name="line461"></a>
<a name="line462"></a>
<a name="line463"></a>
<a name="line464"></a>/**
<a name="line465"></a> * Node list implementation which maintains sort order during insertion and
<a name="line466"></a> * modification operations based on a comparison function.
<a name="line467"></a> *
<a name="line468"></a> * The SortedNodeList does not guarantee sort order will be maintained if
<a name="line469"></a> * the underlying data nodes are modified externally.
<a name="line470"></a> *
<a name="line471"></a> * Names that are reserved for system use and shouldn&#39;t be used for data node
<a name="line472"></a> * names: eval, toSource, toString, unwatch, valueOf, watch. Behavior is
<a name="line473"></a> * undefined if these names are used.
<a name="line474"></a> *
<a name="line475"></a> * @param {Function} compareFn Comparison function by which the
<a name="line476"></a> *     node list is sorted. Should take 2 arguments to compare, and return a
<a name="line477"></a> *     negative integer, zero, or a positive integer depending on whether the
<a name="line478"></a> *     first argument is less than, equal to, or greater than the second.
<a name="line479"></a> * @param {Array.&lt;goog.ds.DataNode&gt;} opt_nodes optional nodes to add to list;
<a name="line480"></a> *    these are assumed to be in sorted order.
<a name="line481"></a> * @extends {goog.ds.BasicNodeList}
<a name="line482"></a> * @constructor
<a name="line483"></a> */
<a name="line484"></a>goog.ds.SortedNodeList = function(compareFn, opt_nodes) {
<a name="line485"></a>  this.compareFn_ = compareFn;
<a name="line486"></a>  goog.ds.BasicNodeList.call(this, opt_nodes);
<a name="line487"></a>};
<a name="line488"></a>goog.inherits(goog.ds.SortedNodeList, goog.ds.BasicNodeList);
<a name="line489"></a>
<a name="line490"></a>
<a name="line491"></a>/**
<a name="line492"></a> * Add a node to the node list, maintaining sort order.
<a name="line493"></a> * If the node has a dataName, uses this for the key in the map.
<a name="line494"></a> *
<a name="line495"></a> * @param {goog.ds.DataNode} node The node to add.
<a name="line496"></a> */
<a name="line497"></a>goog.ds.SortedNodeList.prototype.add = function(node) {
<a name="line498"></a>  if (!this.compareFn_) {
<a name="line499"></a>    this.append(node);
<a name="line500"></a>    return;
<a name="line501"></a>  }
<a name="line502"></a>
<a name="line503"></a>  var searchLoc = goog.array.binarySearch(this.list_, node, this.compareFn_);
<a name="line504"></a>
<a name="line505"></a>  // if there is another node that is &quot;equal&quot; according to the comparison
<a name="line506"></a>  // function, insert before that one; otherwise insert at the location
<a name="line507"></a>  // goog.array.binarySearch indicated
<a name="line508"></a>  if (searchLoc &lt; 0) {
<a name="line509"></a>    searchLoc = -(searchLoc + 1);
<a name="line510"></a>  }
<a name="line511"></a>
<a name="line512"></a>  // update any indexes that are after the insertion point
<a name="line513"></a>  for (var index in this.indexMap_) {
<a name="line514"></a>    if (this.indexMap_[index] &gt;= searchLoc) {
<a name="line515"></a>      this.indexMap_[index]++;
<a name="line516"></a>    }
<a name="line517"></a>  }
<a name="line518"></a>
<a name="line519"></a>  goog.array.insertAt(this.list_, node, searchLoc);
<a name="line520"></a>  var dataName = node.getDataName();
<a name="line521"></a>  if (dataName) {
<a name="line522"></a>    this.map_[dataName] = node;
<a name="line523"></a>    this.indexMap_[dataName] = searchLoc;
<a name="line524"></a>  }
<a name="line525"></a>};
<a name="line526"></a>
<a name="line527"></a>
<a name="line528"></a>/**
<a name="line529"></a> * Adds the given node to the end of the SortedNodeList. This should
<a name="line530"></a> * only be used when the caller can guarantee that the sort order will
<a name="line531"></a> * be maintained according to this SortedNodeList&#39;s compareFn (e.g.
<a name="line532"></a> * when initializing a new SortedNodeList from a list of nodes that has
<a name="line533"></a> * already been sorted).
<a name="line534"></a> * @param {goog.ds.DataNode} node The node to append.
<a name="line535"></a> */
<a name="line536"></a>goog.ds.SortedNodeList.prototype.append = function(node) {
<a name="line537"></a>  goog.ds.SortedNodeList.superClass_.add.call(this, node);
<a name="line538"></a>};
<a name="line539"></a>
<a name="line540"></a>
<a name="line541"></a>/**
<a name="line542"></a> * Sets a node in the list of a given name, maintaining sort order.
<a name="line543"></a> * @param {string} name Name of the node.
<a name="line544"></a> * @param {goog.ds.DataNode} node The node.
<a name="line545"></a> */
<a name="line546"></a>goog.ds.SortedNodeList.prototype.setNode = function(name, node) {
<a name="line547"></a>  if (node == null) {
<a name="line548"></a>    this.removeNode(name);
<a name="line549"></a>  } else {
<a name="line550"></a>    var existingNode = this.indexMap_[name];
<a name="line551"></a>    if (existingNode != null) {
<a name="line552"></a>      if (this.compareFn_) {
<a name="line553"></a>        var compareResult = this.compareFn_(this.list_[existingNode], node);
<a name="line554"></a>        if (compareResult == 0) {
<a name="line555"></a>          // the new node can just replace the old one
<a name="line556"></a>          this.map_[name] = node;
<a name="line557"></a>          this.list_[existingNode] = node;
<a name="line558"></a>        } else {
<a name="line559"></a>          // remove the old node, then add the new one
<a name="line560"></a>          this.removeNode(name);
<a name="line561"></a>          this.add(node);
<a name="line562"></a>        }
<a name="line563"></a>      }
<a name="line564"></a>    } else {
<a name="line565"></a>      this.add(node);
<a name="line566"></a>    }
<a name="line567"></a>  }
<a name="line568"></a>};
<a name="line569"></a>
<a name="line570"></a>
<a name="line571"></a>/**
<a name="line572"></a> * The character denoting an attribute.
<a name="line573"></a> * @type {string}
<a name="line574"></a> * @private
<a name="line575"></a> */
<a name="line576"></a>goog.ds.STR_ATTRIBUTE_START_ = &#39;@&#39;;
<a name="line577"></a>
<a name="line578"></a>
<a name="line579"></a>/**
<a name="line580"></a> * The character denoting all children.
<a name="line581"></a> * @type {string}
<a name="line582"></a> */
<a name="line583"></a>goog.ds.STR_ALL_CHILDREN_SELECTOR = &#39;*&#39;;
<a name="line584"></a>
<a name="line585"></a>
<a name="line586"></a>/**
<a name="line587"></a> * The wildcard character.
<a name="line588"></a> * @type {string}
<a name="line589"></a> */
<a name="line590"></a>goog.ds.STR_WILDCARD = &#39;*&#39;;
<a name="line591"></a>
<a name="line592"></a>
<a name="line593"></a>/**
<a name="line594"></a> * The character denoting path separation.
<a name="line595"></a> * @type {string}
<a name="line596"></a> */
<a name="line597"></a>goog.ds.STR_PATH_SEPARATOR = &#39;/&#39;;
<a name="line598"></a>
<a name="line599"></a>
<a name="line600"></a>/**
<a name="line601"></a> * The character denoting the start of an array.
<a name="line602"></a> * @type {string}
<a name="line603"></a> */
<a name="line604"></a>goog.ds.STR_ARRAY_START = &#39;[&#39;;
<a name="line605"></a>
<a name="line606"></a>
<a name="line607"></a>/**
<a name="line608"></a> * Shared logger instance for data package
<a name="line609"></a> * @type {goog.debug.Logger}
<a name="line610"></a> */
<a name="line611"></a>goog.ds.logger = goog.debug.Logger.getLogger(&#39;goog.ds&#39;);
<a name="line612"></a>
<a name="line613"></a>
<a name="line614"></a>/**
<a name="line615"></a> * Create a data node that references another data node,
<a name="line616"></a> * useful for pointer-like functionality.
<a name="line617"></a> * All functions will return same values as the original node except for
<a name="line618"></a> * getDataName()
<a name="line619"></a> * @param {!goog.ds.DataNode} node The original node.
<a name="line620"></a> * @param {string} name The new name.
<a name="line621"></a> * @return {!goog.ds.DataNode} The new data node.
<a name="line622"></a> */
<a name="line623"></a>goog.ds.Util.makeReferenceNode = function(node, name) {
<a name="line624"></a>  /**
<a name="line625"></a>   * @constructor
<a name="line626"></a>   * @extends {goog.ds.DataNode}
<a name="line627"></a>   */
<a name="line628"></a>  var nodeCreator = function() {};
<a name="line629"></a>  nodeCreator.prototype = node;
<a name="line630"></a>  var newNode = new nodeCreator();
<a name="line631"></a>  newNode.getDataName = function() {
<a name="line632"></a>    return name;
<a name="line633"></a>  };
<a name="line634"></a>  return newNode;
<a name="line635"></a>};
</pre>


</body>
</html>
